package com.kcht.rfid.rd30.test;

import com.kcht.rfid.rd30.secretary.DeviceIntf;
import com.kcht.rfid.rd30.secretary.Rd30Manager;
import com.kcht.rfid.rd30.secretary.core.command.*;
import com.kcht.rfid.rd30.secretary.core.common.LockAction;
import com.kcht.rfid.rd30.secretary.core.common.LockBank;
import com.kcht.rfid.rd30.secretary.core.common.RawTagBank;
import com.kcht.rfid.rd30.secretary.core.common.ReaderCommandType;


public class PlaySecretary {
    public static void main(String[] args) throws InterruptedException {
        DeviceIntf rd30Manager=Rd30Manager.getInstance();
        rd30Manager.initReader("192.168.4.78",null,new NetWork());
        ReaderCommand readerCommand =new ReaderCommand();
        readerCommand.setCommandType(ReaderCommandType.CYCLE);
        readerCommand.addReaderCommand(invent());
        //        readerCommandSet.addReaderCommand(write());
//        readerCommandSet.addReaderCommand(lock());
        readerCommand.addReaderCommand(read());
        rd30Manager.dispatchReaderCommand("192.168.4.78", readerCommand,new LogicReader());
        Thread.sleep(5000);
        readerCommand.setCommandType(ReaderCommandType.SINGLE);
//        rd30Manager.disconnectReader("192.168.4.78");
//        rd30Manager.initReader("192.168.4.78",null,new LogicReader());
//        rd30Manager.stopReaderWork("192.168.4.78");
        ReaderCommand readerCommand2 =new ReaderCommand();
//        readerCommandSet2.addReaderCommand(invent());
//        readerCommandSet2.addReaderCommand(write());
//        readerCommandSet.addReaderCommand(lock());
        readerCommand2.setCommandType(ReaderCommandType.CYCLE);
        readerCommand2.addReaderCommand(read());
        rd30Manager.dispatchReaderCommand("192.168.4.78", readerCommand2,new LogicReader());
        int i=0;
        while(i<100){
            new Thread(()->{
                rd30Manager.dispatchReaderCommand("192.168.4.78", readerCommand2,new LogicReader());
            }).start();
            i++;
        }
    }

    public static WriteCommand write(){
        WriteCommand command=new WriteCommand();
        command.setBank(RawTagBank.RESERVED_BANK);
        command.setOffset(2);
        command.setLength(2);
        command.setValue("11111111");
//        command.setPwd("11111111");
        return command;
    }

    public static ReadCommand read(){
        ReadCommand command=new ReadCommand();
        command.setBank(RawTagBank.USER_BANK);
        command.setOffset(0);
        command.setLength(2);
//        command.setPwd("11111111");
        return command;
    }

    public static LockCommand lock(){
        LockCommand command=new LockCommand();
        command.setPwd("11111111");
        command.setLockBank(LockBank.EPC_BANK);
        command.setLockAction(LockAction.PERMA_UNLOCK);
        return command;
    }

    public static InventoryCommand invent(){
        return new InventoryCommand();
    }

}
